package com.ehi.alliance;

import com.ehi.common.domain.alliance.AllianceInfo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;

//http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-testing.html
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
public class ApplicationTest {

    @Autowired
    private TestRestTemplate restTemplate;

    @Test
    public void test() {
        ResponseEntity<String> entity = this.restTemplate.getForEntity("/echo",
            String.class);
        assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(entity.getBody()).isEqualTo("Hello Spring Boot");
    }

    @Test
    public void testGetCity() {
        ResponseEntity<AllianceInfo> entity = this.restTemplate.getForEntity("/echo/city",
            AllianceInfo.class);
        assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
        assertThat(entity.getBody().getCountyCode()).isEqualTo("NLD");
    }
//	@TestConfiguration
//	static class Config {
//
//		@Bean
//		public RestTemplateBuilder restTemplateBuilder() {
//			return new RestTemplateBuilder().
//
//		}
//
//	}

}
